package cn.edu.zafu.bigdata.x.huangxihao202211080211;

// InterfaceDemo.java
public class InterfaceDemo11 {

    // 接口 Movable
    public interface Movable {
        void move(); // 表示物体移动
        void stop(); // 表示物体停止移动
    }

    // 接口 Resizable
    public interface Resizable {
        void resize(double factor); // 根据因子进行缩放
    }

    // 类 Car 实现 Movable 接口
    public static class Car implements Movable {
        @Override
        public void move() {
            System.out.println("The car is moving.");
        }

        @Override
        public void stop() {
            System.out.println("The car has stopped.");
        }
    }

    // 类 ResizableCircle 实现 Movable 和 Resizable 接口
    public static class ResizableCircle implements Movable, Resizable {
        private double radius;

        public ResizableCircle(double radius) {
            this.radius = radius;
        }

        @Override
        public void move() {
            System.out.println("The circle is moving.");
        }

        @Override
        public void stop() {
            System.out.println("The circle has stopped.");
        }

        @Override
        public void resize(double factor) {
            radius *= factor; // 根据缩放因子修改半径
            System.out.println("The resized radius is: " + radius);
        }
    }

    // 测试类 TestInterface
    public static class TestInterface {
        public static void main(String[] args) {
            Car car = new Car();
            ResizableCircle circle = new ResizableCircle(5);

            // 测试 Car 的实现
            car.move();
            car.stop();

            // 测试 ResizableCircle 的实现
            circle.move();
            circle.stop();
            circle.resize(2); // 缩放因子为 2
        }
    }

    // 主方法
    public static void main(String[] args) {
        TestInterface.main(args);
    }
}
